<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        // new Promise((resolve, reject) => {
        //     console.log('promise')
        //     resolve()
        // }).then(value => {
        //     console.log('成功')
        // })
        // console.log('呵呵')

        //上面代码的执行顺序是 ：  promise   呵呵   成功


        new Promise((resolve, reject) => {
            setTimeout(() => {
                // console.log('setTimeout')
                resolve()
                console.log('setTimeout')
            }, 0)
            
            console.log('promise')
        }).then(value => {
            console.log('成功')
        })
        console.log('呵呵')
        //上面代码的执行顺序是 ： promise  呵呵   setTimeout   成功 
        //代码执行到setTimeout，会把setTimeout里面的任务推入宏任务队列，当宏任务被拿到主线程执行时，会先打印setTimeout，然后创建一个微任务
    </script>
</body>

</html>